<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="video">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

   

    <el-table v-loading="loading" :data="belongingsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="创建时间" align="center" prop="F_CreateDate" />
      <el-table-column label="案件编号" align="center" prop="CasesId" />
      <el-table-column label="案件名称" align="center" prop="CaseName" />
      <el-table-column label="嫌疑人姓名" align="center" prop="SuspectName" />
       <el-table-column label="是否上传" align="center">
        <template
          slot-scope="scope"
        >
          <el-tag
            effect="dark"
            :type="scope.row.state==0 ? 'success' : 'danger'"
            close-transition
            >{{ scope.row.state ==0 ? "是" : "否" }}</el-tag
          >
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBelongings, getBelongings, delBelongings, addBelongings, updateBelongings } from "@/api/business/belongings";

export default {
  name: "Belongings",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 随身物品信息主表格数据
      belongingsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        centerinfoid: [
          { required: true, message: "办案中心Id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询随身物品信息主列表 */
    getList() {
      this.loading = true;
      listBelongings(this.queryParams).then(response => {
        console.log(response);
        this.belongingsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fId: null,
        fEnabledmark: null,
        fCreateuserid: null,
        fDeletemark: null,
        fCreateusername: null,
        fCreatedate: null,
        fDescription: null,
        entryregistrationid: null,
        personneltype: null,
        casesid: null,
        casename: null,
        suspectid: null,
        suspectname: null,
        cabinetid: null,
        cabinetname: null,
        boxid: null,
        boxcode: null,
        positionid: null,
        positioncode: null,
        positionname: null,
        isinput: null,
        centerinfoid: null,
        accesstype: null,
        issave: null,
        savedatetimes: null,
        isuse: null,
        inid: null,
        takedatetimes: null,
        ismyselftake: null,
        takepersonid: null,
        wristbandid: null,
        number: null,
        pdfurl: null,
        managesignature: null,
        suspectsignature: null,
        suspectfingerprint: null,
        managefingerprint: null,
        managesignature2: null,
        suspectsignature2: null,
        suspectfingerprint2: null,
        managefingerprint2: null,
        video: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加随身物品信息主";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fId = row.fId || this.ids
      getBelongings(fId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改随身物品信息主";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fId != null) {
            updateBelongings(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBelongings(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fIds = row.fId || this.ids;
      this.$modal.confirm('是否确认删除随身物品信息主编号为"' + fIds + '"的数据项？').then(function() {
        return delBelongings(fIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/belongings/export', {
        ...this.queryParams
      }, `belongings_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
